// 组合
// 方法 1
var combine = function (n, k) {
  const ans = []
  const dfs = (cur, n, k, temp) => {
    if (temp.length + (n - cur + 1) < k) return
    if (temp.length === k) {
      ans.push(temp)
      return
    }
    dfs(cur + 1, n, k, [...temp, cur])
    dfs(cur + 1, n, k, temp)
  }

  dfs(1, n, k, [])

  return ans
}

// 方法 2
var combine = function (n, k) {
  const temp = []
  const ans = []
  for (let i = 1; i <= k; i++) {
    temp.push(i)
  }
  temp.push(n + 1)
  let j = 0
  while (j < k) {
    ans.push(temp.slice(0, k))
    j = 0
    while (j < k && temp[j] + 1 === temp[j + 1]) {
      temp[j] = j + 1
      j++
    }
    temp[j]++
  }
  return ans
}
